#define _GNU_SOURCE // 引入unistd.h扩展中的gettid()函数
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void *first_thread_func(void *arg)
{
    printf("first线程id:%d\n", gettid()); // 获取线程id
    return NULL;
}

void *second_thread_func(void *arg)
{
    printf("second线程id:%d\n", gettid()); // 获取线程id
    return NULL;
}

int main(int argc, char *argv[])
{
    printf("main线程开始执行!\n");

    pthread_t first;  // 线程标识
    pthread_t second; // 线程标识
    pthread_create(&first, NULL, first_thread_func, NULL);
    pthread_create(&second, NULL, second_thread_func, NULL);

    printf("main线程的ID是:%d\n", gettid()); // 获取线程id

    pthread_join(first, NULL);  // 等待线程结束
    pthread_join(second, NULL); // 等待线程结束

    printf("main线程执行结束!\n");

    return 0;
}